<?php
class  Admin_Model_DbTable_PageCategory  extends  Kieumau_Db_Common
{
	
	public function init(){
		
		parent::init();
		$this->_name = 'page_category';
		$this->fieldsPrimary = array('');
		$this->fieldsLanguage = array('');
	}
	
	public function getPageChildren($categoryId, $languageId){
		try {
			$sql = 'SELECT a.page_id, b.name 
					FROM  '.$this->_name.' a
					LEFT JOIN page_language b
					ON a.page_id = b.page_id
					WHERE  a.category_id = ?
					AND b.lang_id = ?
					';
			$result = $this->_db->fetchAll($sql, array($categoryId,$languageId));
			
			/* ================== DEBUG PART 1
			echo "sql la : $sql";
			echo "<br /> taxonomy_id: $categoryId = languageCode: $languageId";
			echo "<br/>Result:<pre>";
			var_dump($result);
			echo "</pre>";
			/**/
			
			return $result;
    	} catch ( Exception $ex ) {
    		echo $ex->getMessage ();
    	}
	}
	
	public function getByPageId($pageId){
		try {
			$sql = "Select *
					FROM ".$this->_name.
					" WHERE page_id = ?";
			
			$this->_db->setFetchMode(Zend_Db::FETCH_ASSOC);

			$categoryId =  $this->_db->fetchAll ( $sql, $pageId );
			if(!empty($categoryId)){
				return $categoryId[0];
			}else 
				return -1;
		} catch ( Exception $ex ) {
			echo "<br/>Can not get all information, Error: " . $ex->getMessage ();
			//echo "<br/> sql la: ".$sql;
			exit ();
		}
	}
	
}
